home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 12 / Mac Magazin and MacEasy Magazine CD - Issue 12.iso / Sharewarebibliothek / Anwendungen / Wissenschaft & Technik / Yorick / yorick11-nofpu folder / include / movie.i < prev    next >
Text File  |  1995-04-03  |  4KB  |  136 lines

  1. /*
  2.    MOVIE.I
  3.    Support functions for making animated sequences.
  4.  
  5.    $Id$
  6.  */
  7. /*    Copyright (c) 1995.  The Regents of the University of California.
  8.                     All rights reserved.  */
  9.  
  10. func movie(draw_frame, time_limit, min_interframe, bracket_time)
  11. /* DOCUMENT movie, draw_frame
  12.          or movie, draw_frame, time_limit
  13.          or movie, draw_frame, time_limit, min_interframe
  14.      runs a movie based on the given DRAW_FRAME function.  The movie
  15.      stops after a total elapsed time of TIME_LIMIT seconds, which
  16.      defaults to 60 (one minute), or when the DRAW_FRAME function
  17.      returns zero.
  18.  
  19.      func draw_frame(i)
  20.      {
  21.        // Input argument i is the frame number.
  22.        // draw_frame should return non-zero if there are more
  23.        // frames in this movie.  A zero return will stop the
  24.        // movie.
  25.        // draw_frame must NOT include any fma command
  26.      }
  27.  
  28.      If MIN_INTERFRAME is specified, a pauses will be added as
  29.      necessary to slow down the movie.  MIN_INTERFRAME is a time
  30.      in seconds (default 0).
  31.  
  32.      The keyword bracket_time= (again a time in seconds) can be
  33.      used to adjust the duration of the pauses after the first
  34.      and last frames.  It may also be a two element array [beg, end].
  35.      If the pause at the end is greater than five seconds, you will
  36.      be prompted to explain that hitting <RETURN> will abort the final
  37.      pause.
  38.  
  39.      If every frame of your movie has the same limits, use the
  40.      limits command to fix the limits before you call movie.
  41.  
  42.    BUG:  If you hit <RETURN> to start a movie early, it will not
  43.          pause at the end of the movie at all.  You probably should
  44.      not use long initial pauses.
  45.  
  46.    SEE ALSO: movie_stats
  47.  */
  48. {
  49.   if (is_void(time_limit)) time_limit= 60.0;
  50.   if (is_void(min_interframe)) min_interframe= 0.0;
  51.   if (is_void(bracket_time)) bracket_time= [2.,2.];
  52.   else if (numberof(bracket_time)<2) bracket_time= array(bracket_time,2);
  53.  
  54.   elapsed= this_frame= array(0.0, 3);
  55.  
  56.   window, wait=1;  /* make sure window is ready to draw */
  57.   fma;             /* clear out any existing picture */
  58.   animate, 1;
  59.  
  60.   i= 0;
  61.   timer, elapsed;
  62.   elapsed0= elapsed;
  63.   more= draw_frame(++i);
  64.   fma;
  65.   timer, elapsed, this_frame;
  66.   wait= bracket_time(1)-this_frame(3);
  67.   waited= waited0= 0.0;
  68.   if (wait>0) {
  69.     if (wait>5)
  70.       write,
  71.         format="Movie starts in %.0f secs, or when you hit <RETURN>\n", wait;
  72.     pause, long(1000.*wait);
  73.     waited0+= wait;
  74.   } else {
  75.     wait= min_interframe-this_frame(3);
  76.     if (wait>0) {
  77.       pause, long(1000.*wait);
  78.       waited+= wait;
  79.     }
  80.   }
  81.  
  82.   while (more) {
  83.     this_frame()= 0.0;
  84.     more= draw_frame(++i);
  85.     fma;
  86.     timer, elapsed, this_frame;
  87.     if (!more || (elapsed(3)-elapsed0(3))>time_limit) break;
  88.     wait= min_interframe-this_frame(3);
  89.     if (wait>0) {
  90.       pause, long(1000.*wait);
  91.       waited+= wait;
  92.     }
  93.   }
  94.  
  95.   wait= bracket_time(2)-this_frame(3);
  96.   if (wait>0) {
  97.     if (wait>5) {
  98.       write,
  99.         format="Holding last frame for %.0f secs, or hit <RETURN>\n", wait;
  100.       pause, 100;  /* huh? */
  101.     }
  102.     pause, long(1000.*wait);
  103.     waited0+= wait;
  104.   }
  105.   timer, elapsed;
  106.  
  107.   animate, 0;
  108.  
  109.   extern movie_timing;
  110.   movie_timing= grow(elapsed-elapsed0, i, waited, waited0);
  111. }
  112.  
  113. func movie_stats(timing)
  114. /* DOCUMENT movie_stats
  115.          or movie_stats, timing
  116.      prints statistics from the last movie command, or from the
  117.      command which produced TIMING.  TIMING is the contents of the
  118.      movie_timing external variable after the movie command completes.
  119.  
  120.    SEE ALSO: movie
  121.  */
  122. {
  123.   if (is_void(timing)) timing= movie_timing;
  124.   cpu= timing(1)+timing(2);
  125.   wall= timing(3);
  126.   nframes= long(timing(4));
  127.   waited= timing(5)+timing(6);
  128.   wait= timing(5);
  129.  
  130.   write, format="  Wall(sec)  Wait(sec)  CPU(sec)%s\n", "";
  131.   write, format="  %9.3f  %9.3f  %8.3f   %ld frames\n",
  132.          wall, waited, cpu, nframes;
  133.   write, format="  %9.3f  %9.3f  %8.3f   per frame\n",
  134.          (wall-waited)/nframes, wait/(nframes>1?nframes-1:1), cpu/nframes;
  135. }
  136.